<include file="Public/header"/>
<include file="Public/menu"/>

<!-- 内容页 -->
<div class="content-wrapper">
    <!-- 面包屑 -->
    <section class="content-header">
        <h1>
            促销
            <small>组合促销</small>
        </h1>
        <ol class="breadcrumb">
            <li><a href="{:U('Admin/Index/index')}"><i class="fa fa-dashboard"></i> 首页</a></li>
            <li class="active">组合促销</li>
        </ol>
    </section>

    <!-- 内容 -->
    <section class="content">
        <div class="row">
            <div class="col-md-12">
                <div class="nav-tabs-custom">
                    <div class="tab-content">
                        <div class="box-header">
                            <h3 class="box-title">组合促销列表</h3>
                            <div class="form-inline pull-right">
                                <form action="{:U('Promotion/group',array('order_field'=>$order_field,'order'=>$order), '')}"
                                      method="get" pjax-container="">
                                    <fieldset>
                                        <div class="input-group input-group-sm">
                                            <span class="input-group-addon"><strong>促销名称</strong></span>
                                            <input type="hidden" name="search_field" value="name">
                                            <input type="text" class="form-control" placeholder="搜索" name="search"
                                                   value="{$search}">
                                        </div>
                                        <div class="input-group input-group-sm">
                                            <div class="input-group-btn">
                                                <button type="submit" class="btn btn-primary"><i
                                                        class="fa fa-search"></i></button>
                                            </div>
                                        </div>
                                    </fieldset>
                                </form>
                            </div>
                            <div class="btn-group pull-right" style="margin-right: 10px">
                                <a href="{:U('groupAdd')}" class="btn btn-sm btn-success"><i
                                        class="fa fa-save"></i>&nbsp;&nbsp;新增</a>
                            </div>
                        </div>

                        <div class="tab-pane active" id="tab_0">
                            <div class="box">

                                <!-- /.box-header -->
                                <div class="box-body table-responsive no-padding">
                                    <table class="table table-hover" style="width: 100%;">
                                        <tbody>
                                        <tr>
                                            <th>ID<a class="fa fa-fw fa-sort"
                                                     href="{:U('Promotion/group',array('p'=>$p,'order_field'=>'id','order'=>$order), '')}"></a>
                                            </th>
                                            <th>促销名称</th>
                                            <th>总价格</th>
                                            <th>开始时间</th>
                                            <th>结束时间</th>
                                            <th>操作</th>
                                        </tr>
                                        <volist name="list" id="item">
                                            <tr>
                                                <td>{$item.id}</td>
                                                <td>{$item.name}</td>
                                                <td>￥{$item.total_price}</td>
                                                <td>{$item.start_time|date="Y-m-d H:i",###}</td>
                                                <td>{$item.end_time|date="Y-m-d H:i",###}</td>
                                                <td>
                                                    <a href="{:U('Promotion/groupEdit', array('id'=>$item['id']))}"
                                                       class="btn btn-sm btn-primary">查看</a>
                                                    <if condition="!$item['activing']">
                                                    <a data-id="{$item.id}"
                                                       class="btn btn-sm btn-danger grid-refreshe __delete">删除</a>
                                                    </if>
                                                </td>
                                            </tr>
                                        </volist>
                                        </tbody>
                                    </table>
                                </div>
                                <div class="box-footer clearfix">

                                    <a class="btn btn-sm btn-primary grid-refresh"><i class="fa fa-refresh"></i></a>

                                    {$page}

                                </div>
                                <!-- /.box-body -->
                            </div>

                            <!-- 模态框（Modal） -->
                            <div class="modal fade" id="myModallogs" tabindex="-1" role="dialog"
                                 aria-labelledby="myModalLabel" aria-hidden="true">
                                <div class="modal-dialog">
                                    <div class="modal-content">
                                        <div class="modal-header">
                                            <button type="button" class="close" data-dismiss="modal"
                                                    aria-hidden="true">×
                                            </button>
                                            <h4 class="modal-title" id="myModalLabel">
                                                订单状态变更日志
                                            </h4>
                                        </div>
                                        <div class="modal-body">
                                            暂无记录
                                        </div>
                                        <div class="modal-footer">
                                            <button type="button" class="btn btn-default" data-dismiss="modal">
                                                关闭
                                            </button>
                                        </div>
                                    </div><!-- /.modal-content -->
                                </div><!-- /.modal-dialog -->
                            </div><!-- /.modal -->

                        </div>

                        <div class="tab-pane " id="tab_{$k}">
                            <div class="box">
                                <div class="box-body table-responsive no-padding">
                                    {$table}
                                </div>
                            </div>
                        </div>


                    </div>
                </div>
            </div>
        </div>

    </section>
</div>
<!-- 底部 -->
<include file="Public/common_footer"/>

<script data-exec-on-popstate>
    $(function () {
        $('.grid-select-all').change(function () {
            if (this.checked) {
                $('.grid-item').prop("checked", true);
            } else {
                $('.grid-item').prop("checked", false);
            }
        });

        $('.batch-delete').on('click', function (e) {
            if (!confirm("确认批量删除")) {
                return false;
            }
            var data = [];
            $(".grid-item[type='checkbox']:checked").each(function (i) {
                var id = $(this).attr('data-id');
                data.push(id);
            });
            if (data) {
                $.ajax({
                    type: "POST",
                    url: "{:U('Promotion/delGroup')}",
                    data: {id: data},
                    success: function (msg) {
                        alert(msg.message);
                        window.location.reload();
                    },
                    error: function (msg) {
                        alert(msg.message);
                    }
                });
            }
        });

        $('.__delete').click(function () {
            var id = $(this).attr('data-id');
            if (id) {
                $.ajax({
                    type: "POST",
                    url: "{:U('Promotion/delGroup')}",
                    data: {id: id},
                    success: function (msg) {
                       alert(msg.message);
                        window.location.reload();
                    },
                    error: function (msg) {
                        alert(msg.message);
                    }
                });

            }
        });

        $('.__confirm').click(function () {
            $('#myModal').modal('show');
            var purc_id = $(this).attr('data-id');
            var before = $(this).attr('before');
            var status = $(this).attr('status');
            $('#purchase-mark').find('input[name=purc_id]').val(purc_id);
            $('#purchase-mark').find('input[name=before]').val(before);
            $('#purchase-mark').find('input[name=status]').val(status);
        });

        $('._logs').click(function () {
            //$('#myModallogs').modal('show');
            var purc_id = $(this).attr('data-id');
            if (purc_id != '') {
                $.ajax({
                    type: "get",
                    url: "{:U('Promotion/get_purchase_logs')}",
                    data: {purc_id: purc_id},
                    success: function (msg) {
                        $('#myModallogs').modal('show');
                        var html = '';
                        if (msg) {
                            for (var i = 0; i < msg.length; i++) {
                                html += '<p class="message"><a class="name"> <small class="text-muted pull-right"><i class="fa fa-clock-o"></i>';
                                html += msg[i].create_time + '</small>';
                                html += msg[i].manage_name + '</a>&nbsp;&nbsp;&nbsp;&nbsp;将状态变更为：<a>';
                                html += msg[i].later_status + '</a><br><label class="control-label">备注内容：</label>';
                                html += msg[i].desc + '</p>';
                            }
                        }
                        $('#myModallogs').find('.modal-body').html(html);
                    },
                    error: function (msg) {
                        alert(msg.message);
                    }
                });
            } else {
                alert('缺少参数');
            }
        });
    })
</script>